﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace WindowsFormsApplication2
{
    public partial class frmLogin : Form
    {
        private String connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Banco.accdb;";
       
        public frmLogin()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void btnLogar_Click(object sender, EventArgs e)
        {
            int flag = 1;

            if (txtLogin.Text.Equals(""))
            {
                MessageBox.Show("Por Favor Digite o Login", "Anteção", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                flag = 0;
            }
            if (txtSenha.Text.Equals(""))
            {
                MessageBox.Show("Por Favor Digite a Senha", "Anteção", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                flag = 0;
            }
            if (flag == 1)
            {
               
                
                OleDbConnection cnn = new OleDbConnection(connectionString);
                cnn.Open();
                string select = "SELECT * FROM Cliente WHERE login = '" + txtLogin.Text + "' AND senha = '" + txtSenha.Text + "'";
                OleDbCommand verifica = new OleDbCommand(select,cnn);
                bool resultado = verifica.ExecuteReader().HasRows;
                if (resultado == true)
                {
                    cnn.Close();
                    frmPrincipal jan = new frmPrincipal();
                    jan.Show();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Login ou Senha Incorreta", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                

               

                

               
                
            }
        }
    }
}
